//
//  NSString+DCString.m
//  GSDache
//
//  Created by guoshikeji_a on 2018/1/18.
//  Copyright © 2018年 tanyin. All rights reserved.
//

#import "NSString+DCString.h"

@implementation NSString (DCString)

- (NSString *)dc_IdCardAsteriskHandle {
    if (self) {
        /**
         前3位和后4位显示 不足只显示前三位
         */
        NSMutableString *string = [[NSMutableString alloc] initWithString:self];
        if (string.length>7) {
            NSString *result=@"";
            for (int i=0; i<string.length; i++) {
                if (i<3 || i>=(string.length-4)) {
                    result = [result stringByAppendingString:[string substringWithRange:NSMakeRange(i, 1)]];
                }else {
                    result = [result stringByAppendingString:@"*"];
                }
            }
            return result;
        }else {
            NSString *result=@"";
            for (int i=0; i<string.length; i++) {
                if (i<3) {
                    result = [result stringByAppendingString:[string substringWithRange:NSMakeRange(i, 1)]];
                }else {
                    result = [result stringByAppendingString:@"*"];
                }
            }
            return result;
        }
    }
    return self;
}

@end
